package cn.xshi.sys.web;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.xshi.sys.form.SysIpFrozenForm;
import cn.xshi.sys.model.SysIpFrozen;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.xshi.common.annotation.Auth;
import cn.xshi.common.base.BaseAction;
import cn.xshi.common.base.BasePage;
import cn.xshi.common.base.BaseResult;
import cn.xshi.common.entity.OauthAccountEntity;
import cn.xshi.common.util.StringUtil;
import cn.xshi.sys.service.SysIpFrozenService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
/**
 * @Desc 平台IP冻结账户
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@RestController
@RequestMapping("/sysIpFrozen")
@Api(value = "平台IP冻结账户API",tags = "平台IP冻结账户API",description = "平台IP冻结账户API")
public class SysIpFrozenController extends BaseAction {

	@Resource
	private SysIpFrozenService sysIpFrozenService;

	/**
	 * 查询平台IP冻结账户列表并分页
	 * @param sysIpFrozenForm
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@GetMapping(value="/list")
	@Auth(value = "/sysIpFrozen/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@ApiOperation(value="查询平台IP冻结账户列表并分页", notes="查询平台IP冻结账户列表并分页")
	public BasePage<List<SysIpFrozen>> getSysIpFrozenListByCondition(SysIpFrozenForm sysIpFrozenForm,Integer pageNo, Integer pageSize){
		commonHPagerByPageNo(pageNo,pageSize);
		List<SysIpFrozen> sysIpFrozenList = sysIpFrozenService.getSysIpFrozenListByCondition(sysIpFrozenForm);
		PageInfo<SysIpFrozen> page = new PageInfo<SysIpFrozen>(sysIpFrozenList);
		return outPageBootByPageNo(page,pageNo,pageSize);
	}

	/**
	 * 查询单个平台IP冻结账户
	 * @param id
	 */
	@GetMapping(value="/get/{id}")
	@Auth(value = "/sysIpFrozen/get",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@ApiOperation(value="查询单个平台IP冻结账户", notes="查询单个平台IP冻结账户")
	public BaseResult<SysIpFrozen> getSysIpFrozenById(@PathVariable("id") String id){
		SysIpFrozen sysIpFrozen = sysIpFrozenService.getSysIpFrozenById(id);
		if(!StringUtil.isEmpty(sysIpFrozen.getCreateId())){
			OauthAccountEntity createBy = getAccount(sysIpFrozen.getCreateId());
			if(null != createBy){
				sysIpFrozen.setCreateBy(createBy.getName());
			}
		}
		if(!StringUtil.isEmpty(sysIpFrozen.getUpdateId())){
			OauthAccountEntity modifiedBy = getAccount(sysIpFrozen.getUpdateId());
			if(null != modifiedBy){
				sysIpFrozen.setModifiedBy(modifiedBy.getName());
			}
		}
		return outDataStr(sysIpFrozen);
	}

	/**
	 * 查询全部平台IP冻结账户
	 * @return
	 */
	@GetMapping(value="/lists")
	@Auth(value = "/sysIpFrozen/lists",authenticationType = Auth.AuthorizationType.NOT_REQUIRED_LOGIN)
	@ApiOperation(value="查询全部平台IP冻结账户", notes="查询全部平台IP冻结账户")
	public BaseResult lists(){
		SysIpFrozenForm sysIpFrozenForm = new SysIpFrozenForm();
		sysIpFrozenForm.setStatus(2);
		List<SysIpFrozen> sysIpFrozenList = sysIpFrozenService.getSysIpFrozenListByCondition(sysIpFrozenForm);
		return outDataStr(sysIpFrozenList);
	}

	/**
	 * 添加
	 * @param sysIpFrozen
	 */
	@PostMapping(value="/add")
	@ApiOperation(value="创建单个平台IP冻结账户 ", notes="创建单个平台IP冻结账户")
	public BaseResult addSysIpFrozen(@RequestBody SysIpFrozen sysIpFrozen){
		int i = 0;
		if(null != sysIpFrozen){
			sysIpFrozen.setId(toUUID());
			i= sysIpFrozenService.addSysIpFrozen(sysIpFrozen);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 修改
	 * @param sysIpFrozen
	 */
	@PutMapping(value="/update")
	@ApiOperation(value="编辑单个平台IP冻结账户 ", notes="编辑单个平台IP冻结账户")
	public BaseResult updateSysIpFrozen(@RequestBody SysIpFrozen sysIpFrozen){
		int i = 0;
		if(null != sysIpFrozen){
			i= sysIpFrozenService.updateSysIpFrozen(sysIpFrozen);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 删除
	 * @param id
	 */
	@DeleteMapping(value="/delete")
	@ApiOperation(value="删除平台IP冻结账户 ", notes="删除平台IP冻结账户")
	public BaseResult delSysIpFrozen(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i= sysIpFrozenService.delSysIpFrozen(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
}